< previous page page_403 next page >

Page 403
9f31265bb40b592b1929e18a47ab28e5.gif
         Open mstrFileName For Input As #mintHandle
      Else
         Open mstrFileName For Output As #mintHandle
      End If

      OpenTextFile = True
   Else
      OpenTextFile = False
   End If
End Function
In the OpenTextFile() method, you first set your module-level variables with the argument values that were passed in. Next, you check the mode to see whether youll be opening the file for reading or appending. If youre opening the file for reading, youll use the For Input option of the Open statement. If youre opening the file for appending or writing, youll use the For Output or For Append option of the Open statement.
The Class_Initialize() Event
Prior to opening a text file with the low-level file I/O commands in Visual Basic, you must first retrieve a file handle from the operating system. This is accomplished with the FreeFile statement. This statement is located in the Class_Initialize() event of the TextStream class:
9f31265bb40b592b1929e18a47ab28e5.gif
Private Sub Class_Initialize()
      mintHandle = FreeFile
End Sub
Each time a new instance of the TextStream class is instantiated, a new file handle will be retrieved from the operating system.
Adding Data to the Text File
After the text file is opened, the WriteLine() method is used to write the data to the text file. The WriteLine() method takes whatever data is passed into it as an argument and appends that data to the file:
9f31265bb40b592b1929e18a47ab28e5.gif
Public Function WriteLine(_
      Optional strWrite As String = vbCrLf) As Boolean

   If mintHandle <> 0 Then

 
< previous page page_403 next page >

If you like this book, buy it!